<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>新闻展示</title>
    <link href="../css/style.css" type="text/css" rel="stylesheet">
    <script src="../js/jquery-1.8.3.js"></script>
    <script src="../js/jquery-1.8.3.min.js"></script>
    <script src="../js/NewsItems.js"></script>
</head>
<body>
    <p style="text-align: right;padding-right: 50px;">
    <c:if test="${sessionScope.u == null }">
    	<a href="../user/goLogin.html">登陆</a>&nbsp;&nbsp;||&nbsp;&nbsp;
    	<a href="../user/goRegist.html">注册</a>
    </c:if>
    <c:if test="${sessionScope.u != null }">
       	 欢迎您:${sessionScope.u.userName }&nbsp;&nbsp;&nbsp;&nbsp;${pageContext.request.contextPath }
        <a href="../user/goUserManager.html">后台管理</a>
    </c:if>
    </p>
    <h1 style="font-size: 30px;text-align: center;">新闻资讯</h1>
    <form action="../news/goNewsItems.html" method="get">
    	<table class="searchTableClass">
    		<tr>
    			<td>主题</td>
    			<td>
    				<select name="unit">
						<option value="" <c:if test="${unit=='' }"> selected="selected"</c:if> >所有模块</option>
						<option value="公告" <c:if test="${unit=='公告' }"> selected="selected" </c:if> >公告</option>
						<option value="促销" <c:if test="${unit=='促销' }"> selected="selected" </c:if> >促销</option>
						<option value="新品" <c:if test="${unit=='新款' }"> selected="selected" </c:if> >新品</option>
					</select>
    			</td>
    			<td>标题</td>
    			<td>
    				<input type="search" name="title" value="${title}">
    			</td>
    			<td>开始时间</td>
    			<td>
    				<input type="date" name="startTime" value="${startTime}">
    			</td>
    			<td>结束时间</td>    			
    			<td>
    				<input type="date" name="endTime" value="${endTime}">
    			</td>    			
    			<td>
    				<input type="submit" value="搜索" id="selectNews" >
    			</td>
    		</tr>
    	</table>
    </form>
    <table border="1" class="newsItemsTableId">
        <tr>
            <td width="100">新闻ID</td>
            <td width="100">新闻模块</td>
            <td width="250">新闻标题</td>
            <td width="350">新闻内容</td>
            <td width="250">发布时间</td>
        </tr>
        <c:forEach items="${nl }" var="n">
	        <tr>
	            <td width="100">${n.id }</td>
	            <td width="100">${n.unit }</td>
	            <td width="300">${n.title }</td>
	            <td width="300">
	            	<c:choose>
						<c:when test="${fn:length(n.content) >10 }">
							${fn:substring(n.content,0,10) }...
						</c:when>
						<c:otherwise>
							${n.content }
						</c:otherwise>	
	            	</c:choose>
				</td>
	            <td width="250"><fmt:formatDate value="${n.createTime }"  pattern="yyyy-MM-dd HH:mm:ss"/></td>
	        </tr>
        </c:forEach>
    </table>
    
    <div class="pageSize">
    
    
    	<c:if test="${cp==1 }">
	        <a href="javascript:void(0)">第一页</a>
	        <a href="javascript:void(0)">上一页</a>
    	</c:if>
    	<c:if test="${cp!=1 }">
	        <a href="../news/goNewsItems.html?cp=${1 }&unit=${unit}&title=${title}&startTime=${startTime}&endTime=${endTime}">第一页</a>
	        <a href="../news/goNewsItems.html?cp=${cp-1 }&unit=${unit}&title=${title}&startTime=${startTime}&endTime=${endTime}">上一页</a>
    	</c:if>

        <c:forEach var="i" begin="1" end="${pc }">
        	<c:if test="${cp!=i }">
	        	<a href="../news/goNewsItems.html?cp=${i }&unit=${unit}&title=${title}&startTime=${startTime}&endTime=${endTime}" >${i }</a>
        	</c:if>
        	<c:if test="${cp==i }">
	        	<a href="javascript:void(0)" style="background: red;color: white">${i }</a>
        	</c:if>
        </c:forEach>
        
        <c:if test="${cp==pc }">
	        <a href="javascript:void(0)">下一页</a>
        	<a href="javascript:void(0)">最后一页</a>
    	</c:if>
    	<c:if test="${cp!=pc }">
	        <a href="../news/goNewsItems.html?cp=${cp+1 }&unit=${unit}&title=${title}&startTime=${startTime}&endTime=${endTime}">下一页</a>
        	<a href="../news/goNewsItems.html?cp=${pc}&unit=${unit}&title=${title}&startTime=${startTime}&endTime=${endTime}">最后一页</a>
    	</c:if>
    	
	    <form action="../news/goNewsItems.html" method="get">
	    	<input type="number" name="cp" value="${cp }" max="${pc }" min="1" >
	    	<input type="hidden" name="unit" value="${unit }">
	    	<input type="hidden" name="title" value="${title }">
	    	<input type="hidden" name="startTime" value="${startTime }">
	    	<input type="hidden" name="endTime" value="${endTime }">
	    	<input type="submit" value="搜索">
	    </form>
    </div> 
</body>
</html>